package com.bocai.kelala.ui.travel.set.act;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.kelala.App;
import com.bocai.kelala.R;
import com.bocai.kelala.base.BaseActivity;
import com.bocai.kelala.bean.MyInvoiceBean;
import com.bocai.kelala.bean.MyInvoiceDetailBean;
import com.bocai.kelala.ui.travel.main.act.MainActivity;
import com.bocai.kelala.ui.travel.set.contract.MyInvoiceContract;
import com.bocai.kelala.ui.travel.set.module.MyInvoiceModule;
import com.bocai.kelala.ui.travel.set.presenter.MyInvoicePresenter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuanfei on 2017/6/12.
 */

public class MyInvoiceStatusActivity extends BaseActivity implements MyInvoiceContract.view {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.right_btn)
    Button rightBtn;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_head_invoice)
    TextView tvHeadInvoice;
    @BindView(R.id.tv_address_detail)
    TextView tvAddressDetail;
    @BindView(R.id.tv_address_name)
    TextView tvAddressName;
    @BindView(R.id.tv_address_phone)
    TextView tvAddressPhone;
    @BindView(R.id.tv_invoice_num)
    TextView tvInvoiceNum;
    @BindView(R.id.tv_customer_service_phone)
    TextView tvCustomerServicePhone;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @Inject
    MyInvoicePresenter presenter;
    String orderId;

    @Override
    public int getLayoutId() {
        return R.layout.act_my_invoice_status;
    }

    @Override
    public void initPresenter() {
        App.get(this).getAppComponent().addSub(new MyInvoiceModule(this)).inject(this);
    }

    @Override
    public void initView() {
        initToolbar("我的发票");
        initBack(imgBack,llBack);
        orderId = getIntent().getStringExtra("orderId");
        presenter.invoiceDetail(orderId);

    }

    @Override
    public void getMyInvoiceList(MyInvoiceBean bean) {

    }

    @Override
    public void openInvoiceSuccess() {

    }

    @Override
    public void getInvoiceDetail(MyInvoiceDetailBean bean) {
        tvHeadInvoice.setText(bean.getInvoice());
        tvAddressDetail.setText(bean.getShippingAddress());
        tvAddressPhone.setText(bean.getPhone());
        tvAddressName.setText(bean.getConsignee());
        if (TextUtils.isEmpty(bean.getShippingNo())){
            tvInvoiceNum.setText("暂无运单号");
        }else {
            tvInvoiceNum.setText(bean.getShippingName()+":"+bean.getShippingNo());
        }
    }

    @Override
    public void showLoading(String title) {
        startProgressDialog(title);
    }

    @Override
    public void stopLoading() {
    stopProgressDialog();
    }

    @Override
    public void showErrorTip(String msg) {

        if (msg.equals("用户授权失败")){
            msg = "您的登录已失效，请重新登录";
            startActivity(new Intent(this,MainActivity.class).putExtra("index",1));
            finish();
        }
        showShortToast(msg);
    }
}
